package com.market.interceptor;

import com.market.enums.RoleEnum;
import com.market.utils.TokenUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @ClassName CSStaffInterceptor
 * @Description TODO
 * @Author 1
 * @Date 2022/4/10 16:46
 * @Version 1.0
 */
@Configuration
public class CSStaffInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag=false;
        String token=request.getHeader("Token");
        if(token==null){
            System.out.println("您还未登录，请先登录");
            return false;
        }
        Map<String, Object> map = TokenUtil.parseToken(token);
        if(map.get("role").equals(RoleEnum.CS_STAFF.getRoleName())){
            System.out.println("客服人员登录");
            flag=true;
        }else{
            System.out.println("非法登录");
        }
        return flag;
    }
}
